#include "Vector2.h"

Vector2 Vector2::operator+(const Vector2& vec) const
{
    return {x + vec.x, y + vec.y};
}

void Vector2::operator+=(const Vector2& vec)
{
    x += vec.x, y += vec.y;
}

Vector2 Vector2::operator-(const Vector2& vec) const
{
    return {x - vec.x, y - vec.y};
}

void Vector2::operator-=(const Vector2& vec)
{
    x -= vec.x, y -= vec.y;
}

double Vector2::operator*(const Vector2& vec) const
{
    return x * vec.x + y * vec.y;
}

Vector2 Vector2::operator*(double val) const
{
    return {x * val, y * val};
}

void Vector2::operator*=(double val)
{
    x *= val, y *= val;
}

bool Vector2::operator==(const Vector2& vec) const
{
    return x == vec.x && y == vec.y;
}

bool Vector2::operator>(const Vector2& vec) const
{
    return Length() > vec.Length();
}

bool Vector2::operator<(const Vector2& vec) const
{
    return Length() < vec.Length();
}

double Vector2::Length() const
{
    return sqrt(x * x + y * y);
}

Vector2 Vector2::Normalize() const
{
    double len = Length();
    if (len == 0) {
        return {0, 0};
    }
    return {x / len, y / len};
}

bool Vector2::ApproxZero() const
{
    return Length() < 0.0001;
}